<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.2">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"wrr123.github.io","root":"/","scheme":"Muse","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.json"};
  </script>

  <meta name="description" content="talk is cheap, show me the code">
<meta property="og:type" content="website">
<meta property="og:title" content="一缕烟气">
<meta property="og:url" content="https://wrr123.github.io/page/30/index.html">
<meta property="og:site_name" content="一缕烟气">
<meta property="og:description" content="talk is cheap, show me the code">
<meta property="og:locale" content="zh_CN">
<meta property="article:author" content="田园隐士">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="https://wrr123.github.io/page/30/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : true,
    isPost : false,
    lang   : 'zh-CN'
  };
</script>

  <title>一缕烟气</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<link rel="alternate" href="/atom.xml" title="一缕烟气" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">一缕烟气</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">沧海月明珠有泪，蓝田日暖玉生烟</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content index posts-expand">
            
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://wrr123.github.io/2020/08/06/chrome%E6%8E%A7%E5%88%B6%E5%8F%B0%E7%9A%84%E4%B8%80%E4%BA%9B%E8%AD%A6%E5%91%8A/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="田园隐士">
      <meta itemprop="description" content="talk is cheap, show me the code">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一缕烟气">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2020/08/06/chrome%E6%8E%A7%E5%88%B6%E5%8F%B0%E7%9A%84%E4%B8%80%E4%BA%9B%E8%AD%A6%E5%91%8A/" class="post-title-link" itemprop="url">chrome控制台的一些警告</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-08-06 10:36:37" itemprop="dateCreated datePublished" datetime="2020-08-06T10:36:37+08:00">2020-08-06</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2022-02-18 10:52:04" itemprop="dateModified" datetime="2022-02-18T10:52:04+08:00">2022-02-18</time>
              </span>

          <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>285</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>1 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h4 id="DevTools-failed-to-load-SourceMap-could-not-load-content-for-bootstrap-min-css-map-404-……"><a href="#DevTools-failed-to-load-SourceMap-could-not-load-content-for-bootstrap-min-css-map-404-……" class="headerlink" title="DevTools failed to load SourceMap: could not load content for bootstrap.min.css.map 404 ……"></a>DevTools failed to load SourceMap: could not load content for bootstrap.min.css.map 404 ……</h4><h5 id="解决方案"><a href="#解决方案" class="headerlink" title="解决方案"></a>解决方案</h5><ol>
<li><p>使用官网的css文件</p>
</li>
<li><p>从官网下载<code>bootstrap.min.css.map</code>文件放到本地服务器上</p>
</li>
<li><p>修改chrome浏览器的设置</p>
<p><img src="http://localhost:4000/2020/08/06/chrome%E6%8E%A7%E5%88%B6%E5%8F%B0%E7%9A%84%E4%B8%80%E4%BA%9B%E8%AD%A6%E5%91%8A/001.png" alt></p>
</li>
</ol>
<h4 id="Synchronous-XMLHttpRequest-on-the-main-thread-is-deprecated-because-of-its-detrimental-effects-to-the-end-user’s-experience"><a href="#Synchronous-XMLHttpRequest-on-the-main-thread-is-deprecated-because-of-its-detrimental-effects-to-the-end-user’s-experience" class="headerlink" title="Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user’s experience"></a>Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user’s experience</h4><h5 id="原因："><a href="#原因：" class="headerlink" title="原因："></a>原因：</h5><p>chrome认为ajax在主线程中应该都是异步的，才没有不利的影响。</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://wrr123.github.io/2020/08/05/git%E5%B8%B8%E8%A7%81%E5%91%BD%E4%BB%A4%E7%9A%84%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="田园隐士">
      <meta itemprop="description" content="talk is cheap, show me the code">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一缕烟气">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2020/08/05/git%E5%B8%B8%E8%A7%81%E5%91%BD%E4%BB%A4%E7%9A%84%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8/" class="post-title-link" itemprop="url">git常见命令的基本使用</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-08-05 16:40:22" itemprop="dateCreated datePublished" datetime="2020-08-05T16:40:22+08:00">2020-08-05</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2022-02-18 10:52:04" itemprop="dateModified" datetime="2022-02-18T10:52:04+08:00">2022-02-18</time>
              </span>

          <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>1.7k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>2 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h4 id="git-restore命令的使用"><a href="#git-restore命令的使用" class="headerlink" title="git-restore命令的使用"></a>git-restore命令的使用</h4><h5 id="一个例子"><a href="#一个例子" class="headerlink" title="一个例子"></a>一个例子</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">1. take a file out of another commit</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">2. restore hello.c from the index</span></span><br><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">git switch master</span></span><br><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">git restore --<span class="built_in">source</span> master~2 Makefile  (1)</span></span><br><span class="line"><span class="meta prompt_">$ </span><span class="language-bash"><span class="built_in">rm</span> -f hello.c</span></span><br><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">git restore hello.c                     (2)</span></span><br></pre></td></tr></table></figure>
<h5 id="git-restore-lt-file-gt-和git-restore-staged的区别"><a href="#git-restore-lt-file-gt-和git-restore-staged的区别" class="headerlink" title="git restore &lt;file&gt;和git restore --staged的区别"></a><code>git restore &lt;file&gt;</code>和<code>git restore --staged</code>的区别</h5><ul>
<li><code>git store</code> 将不再暂存区的文件撤销更改</li>
<li><code>git restore --staged</code> 将文件从暂存区撤出，<strong>但不会撤销文件的更改</strong></li>
</ul>
<h5 id="使用-source参数将文件恢复到和某一次的提交一样"><a href="#使用-source参数将文件恢复到和某一次的提交一样" class="headerlink" title="使用--source参数将文件恢复到和某一次的提交一样"></a>使用<code>--source</code>参数将文件恢复到和某一次的提交一样</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">在工作副本和索引中的内容都与三次提交之前相同</span></span><br><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">git restore --<span class="built_in">source</span> HEAD~3 --staged --worktree main.c</span></span><br></pre></td></tr></table></figure>
<h4 id="将文件还原到某个版本"><a href="#将文件还原到某个版本" class="headerlink" title="将文件还原到某个版本"></a>将文件还原到某个版本</h4><figure class="highlight shell"><figcaption><span>script</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"> 找到文件需要回滚到的版本号(如 cf7a7a38)</span><br><span class="line">git log package-lock.json</span><br><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">git update-index --assume-unchanged fileName</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">利用 checkout 命令即可</span></span><br><span class="line">git checkout cf7a7a38 package-lock.json</span><br></pre></td></tr></table></figure>
<h4 id="git-忽略已经提交过的文件"><a href="#git-忽略已经提交过的文件" class="headerlink" title="git 忽略已经提交过的文件"></a>git 忽略已经提交过的文件</h4><figure class="highlight shell"><figcaption><span>script</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">git update-index --assume-unchanged fileName</span></span><br></pre></td></tr></table></figure>
<h4 id="git-tag-打标签"><a href="#git-tag-打标签" class="headerlink" title="git tag 打标签"></a>git tag 打标签</h4><h5 id="列出标签"><a href="#列出标签" class="headerlink" title="列出标签"></a>列出标签</h5><p><code>git tag &lt;-l&gt; &lt;--list&gt;</code></p>
<blockquote>
<p> <strong>注意：</strong>按照通配符列出标签需要 <code>-l</code> 或 <code>--list</code> 选项</p>
<p>如果你只想要完整的标签列表，那么运行 <code>git tag</code> 就会默认假定你想要一个列表，它会直接给你列出来， 此时的 <code>-l</code> 或 <code>--list</code> 是可选的。</p>
<p>然而，如果你提供了一个匹配标签名的通配模式，那么 <code>-l</code> 或 <code>--list</code> 就是强制使用的。</p>
</blockquote>
<h5 id="创建标签"><a href="#创建标签" class="headerlink" title="创建标签"></a>创建标签</h5><ol>
<li><p>轻量标签</p>
<p> 一个栗子：</p>
 <figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">$ git tag v1.4-lw</span><br><span class="line">$ git tag</span><br><span class="line">v0.1</span><br><span class="line">v1.3</span><br><span class="line">v1.4</span><br><span class="line">v1.4-lw</span><br><span class="line">v1.5</span><br></pre></td></tr></table></figure>
</li>
<li><p>附注标签</p>
<p> 一个栗子：</p>
 <figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">$ git tag -a v1.4 -m <span class="string">&quot;my version 1.4&quot;</span></span><br><span class="line">$ git tag</span><br><span class="line">v0.1</span><br><span class="line">v1.3</span><br><span class="line">v1.4</span><br></pre></td></tr></table></figure>
</li>
</ol>
<h5 id="后期打标签"><a href="#后期打标签" class="headerlink" title="后期打标签"></a>后期打标签</h5><p><code>$ git tag -a v1.2 9fceb02</code></p>
<h5 id="共享标签"><a href="#共享标签" class="headerlink" title="共享标签"></a>共享标签</h5><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">$ git push origin v1.5</span><br><span class="line">Counting objects: 14, <span class="keyword">done</span>.</span><br><span class="line">Delta compression using up to 8 threads.</span><br><span class="line">Compressing objects: 100% (12/12), <span class="keyword">done</span>.</span><br><span class="line">Writing objects: 100% (14/14), 2.05 KiB | 0 bytes/s, <span class="keyword">done</span>.</span><br><span class="line">Total 14 (delta 3), reused 0 (delta 0)</span><br><span class="line">To git@github.com:schacon/simplegit.git</span><br><span class="line"> * [new tag]         v1.5 -&gt; v1.5</span><br></pre></td></tr></table></figure>
<p>若想要一次性推送多个标签，可以使用<code>--tags</code>选项</p>
<p>一个栗子：</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">$ git push origin --tags</span><br><span class="line">Counting objects: 1, <span class="keyword">done</span>.</span><br><span class="line">Writing objects: 100% (1/1), 160 bytes | 0 bytes/s, <span class="keyword">done</span>.</span><br><span class="line">Total 1 (delta 0), reused 0 (delta 0)</span><br><span class="line">To git@github.com:schacon/simplegit.git</span><br><span class="line"> * [new tag]         v1.4 -&gt; v1.4</span><br><span class="line"> * [new tag]         v1.4-lw -&gt; v1.4-lw</span><br></pre></td></tr></table></figure>
<h5 id="删除标签"><a href="#删除标签" class="headerlink" title="删除标签"></a>删除标签</h5><p>删除本地仓库上的标签 git tag -d <tagname></tagname></p>
<p>一个删除轻量标签的栗子：</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ git tag -d v1.4-lw</span><br><span class="line">Deleted tag <span class="string">&#x27;v1.4-lw&#x27;</span> (was e7d5add)</span><br></pre></td></tr></table></figure>
<p>删除远程仓库的标签</p>
<p>第一种方法</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">$ git push origin :refs/tags/v1.4-lw</span><br><span class="line">To /git@github.com:schacon/simplegit.git</span><br><span class="line"> - [deleted]         v1.4-lw</span><br></pre></td></tr></table></figure>
<p>第二种方法</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ git push origin --delete &lt;tagname&gt;</span><br></pre></td></tr></table></figure>
<h5 id="检出标签"><a href="#检出标签" class="headerlink" title="检出标签"></a>检出标签</h5><p>一个栗子：</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ git checkout -b version2 v2.0.0</span><br></pre></td></tr></table></figure>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://wrr123.github.io/2020/08/05/css/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="田园隐士">
      <meta itemprop="description" content="talk is cheap, show me the code">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一缕烟气">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2020/08/05/css/" class="post-title-link" itemprop="url">css</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-08-05 14:20:38" itemprop="dateCreated datePublished" datetime="2020-08-05T14:20:38+08:00">2020-08-05</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2022-02-18 10:52:04" itemprop="dateModified" datetime="2022-02-18T10:52:04+08:00">2022-02-18</time>
              </span>

          <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>7.9k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>7 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h4 id="css中的单位"><a href="#css中的单位" class="headerlink" title="css中的单位"></a>css中的单位</h4><h5 id="视口单位-Viewport-units"><a href="#视口单位-Viewport-units" class="headerlink" title="视口单位(Viewport units)"></a>视口单位(Viewport units)</h5><ul>
<li>vw</li>
<li>vh</li>
</ul>
<h5 id="什么是视口"><a href="#什么是视口" class="headerlink" title="什么是视口"></a>什么是视口</h5><blockquote>
<p>Peter-Paul Koch（”PPK大神”）提出视口的解释是：在桌面端，视口指的是在桌面端，指的是浏览器的可视区域；而在移动端，它涉及3个视口：Layout Viewport（布局视口），Visual Viewport（视觉视口），Ideal Viewport（理想视口）。</p>
</blockquote>
<h5 id="vw-vh和-的区别"><a href="#vw-vh和-的区别" class="headerlink" title="vw/vh和%的区别"></a>vw/vh和%的区别</h5><div class="table-container">
<table>
<thead>
<tr>
<th>单位</th>
<th>解释</th>
</tr>
</thead>
<tbody>
<tr>
<td>vw</td>
<td>1vw=视口宽度的1%</td>
</tr>
<tr>
<td>vh</td>
<td>1vh=视口高度的1%</td>
</tr>
<tr>
<td>vmin</td>
<td>选取vw和vh中最小的那个</td>
</tr>
<tr>
<td>vmax</td>
<td>选取vw和vh中最大的那个</td>
</tr>
</tbody>
</table>
</div>
<div class="table-container">
<table>
<thead>
<tr>
<th>单位</th>
<th>依赖于</th>
</tr>
</thead>
<tbody>
<tr>
<td>%</td>
<td>祖先元素</td>
</tr>
<tr>
<td>vh/vw</td>
<td>视口的尺寸</td>
</tr>
</tbody>
</table>
</div>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/2020/08/05/css/#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://wrr123.github.io/2020/08/05/js%E4%B8%AD%E7%9A%84async%E5%92%8Cawait%E5%85%B3%E9%94%AE%E5%AD%97/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="田园隐士">
      <meta itemprop="description" content="talk is cheap, show me the code">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一缕烟气">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2020/08/05/js%E4%B8%AD%E7%9A%84async%E5%92%8Cawait%E5%85%B3%E9%94%AE%E5%AD%97/" class="post-title-link" itemprop="url">js中的async和await关键字</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-08-05 10:27:21" itemprop="dateCreated datePublished" datetime="2020-08-05T10:27:21+08:00">2020-08-05</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2022-02-18 10:52:04" itemprop="dateModified" datetime="2022-02-18T10:52:04+08:00">2022-02-18</time>
              </span>

          <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>1.4k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>1 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h4 id="Promise"><a href="#Promise" class="headerlink" title="Promise"></a>Promise</h4><p>Promise，简单的说是一个容器，里面保存着某个未来才会结束的时间(通常是一个异步操作的结果)。</p>
<p>Promise 是一个对象，它代表了一个异步操作的最终完成或失败。</p>
<p>本质上 Promise 是一个函数返回的对象，我们可以在它上面绑定回调函数，这样我们就不需要在一开始把回调函数作为参数传入这个函数了。</p>
<h5 id="约定"><a href="#约定" class="headerlink" title="约定"></a>约定</h5><p>不同于老式的传入 ‘回调’, 在使用 Promise 时，会有如下的约定：</p>
<ul>
<li>在本轮 <code>事件循环</code> 运行完成之前，回调函数是不会被调用的。</li>
<li>即使异步操作已经完成（成功或者失败），在这之后通过 <code>then()</code> 添加的函数也会被调用。</li>
<li>通过多次调用 <code>then()</code> 可以添加多个回调函数，它们会按照插入顺序依次执行。<br><em>Promise 很棒的一点就是 <code>链式调用</code></em></li>
</ul>
<h6 id="老式传入-回调-函数的改造"><a href="#老式传入-回调-函数的改造" class="headerlink" title="老式传入 回调 函数的改造"></a>老式传入 <code>回调</code> 函数的改造</h6><ol>
<li>setTimeout(function() {…}, 1000)<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> <span class="title function_">wait</span> = ms =&gt; <span class="keyword">new</span> <span class="title class_">Promise</span>(<span class="function"><span class="params">resolve</span> =&gt;</span> <span class="built_in">setTimeout</span>(resolve, ms))</span><br><span class="line"><span class="title function_">wait</span>(<span class="number">1000</span>).<span class="title function_">then</span>(<span class="function">() =&gt;</span> <span class="title function_">saySomething</span>(<span class="string">&#x27;10 seconds&#x27;</span>)).<span class="title function_">catch</span>(failureCallback)</span><br></pre></td></tr></table></figure>
</li>
</ol>
<h5 id="组合"><a href="#组合" class="headerlink" title="组合"></a>组合</h5><p><code>Promise.resolve()</code> 和 <code>Promise.reject()</code> 是手动创建一个已经 resolve 或者 reject 的 Promise 快捷方法。</p>
<p><code>Promise.all()</code> 和 <code>Promise.race()</code> 是并行运行异步操作的两个组合式工具。</p>
<p>通常，我们递归调用一个由异步函数组成的数组时，相当于一个 Promise 链。<br><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">[func1, func2, func3].<span class="title function_">reduce</span>(<span class="function">(<span class="params">p, f</span>) =&gt;</span> p.<span class="title function_">then</span>(f), <span class="title class_">Promise</span>.<span class="title function_">resolve</span>())</span><br><span class="line">.<span class="title function_">then</span>(<span class="function"><span class="params">result3</span> =&gt;</span> &#123; <span class="comment">/* use result3 */</span> &#125;);</span><br><span class="line"></span><br><span class="line"><span class="title class_">Promise</span>.<span class="title function_">resolve</span>().<span class="title function_">then</span>(func1).<span class="title function_">then</span>(func2).<span class="title function_">then</span>(func3);</span><br></pre></td></tr></table></figure></p>
<h5 id="promise对象的基本语法"><a href="#promise对象的基本语法" class="headerlink" title="promise对象的基本语法"></a>promise对象的基本语法</h5><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">new</span> <span class="title class_">Promise</span>(<span class="function">(<span class="params">resolve,reject</span>) =&gt;</span> &#123;</span><br><span class="line">    <span class="comment">//.....</span></span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>
<h4 id="async-await起到什么作用"><a href="#async-await起到什么作用" class="headerlink" title="async/await起到什么作用"></a>async/await起到什么作用</h4><blockquote>
<p><code>async/await</code>从字面意思上很好理解，<code>async</code>是异步的意思，<code>await</code>有等待的意思，而两者的用法上也是如此。<code>async</code>用于申明一个<code>function</code>是异步的，而<code>await</code> 用于等待一个异步方法执行完成。</p>
</blockquote>
<h5 id="async-await中的错误处理"><a href="#async-await中的错误处理" class="headerlink" title="async/await中的错误处理"></a>async/await中的错误处理</h5><ul>
<li>用try-catch来做错误捕捉</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">async</span> <span class="keyword">function</span> <span class="title function_">myFunction</span>(<span class="params"></span>) &#123;</span><br><span class="line">  <span class="keyword">try</span> &#123;</span><br><span class="line">    <span class="keyword">await</span> <span class="title class_">Promise</span>.<span class="title function_">reject</span>(<span class="string">&#x27;1&#x27;</span>);</span><br><span class="line">  &#125; <span class="keyword">catch</span> (err) &#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(err);</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="title function_">myFunction</span>(); <span class="comment">// 1</span></span><br></pre></td></tr></table></figure>
<ul>
<li>用promise的catch来做错误捕捉</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">async</span> <span class="keyword">function</span> <span class="title function_">myFunction</span>(<span class="params"></span>) &#123;</span><br><span class="line">    <span class="keyword">await</span> <span class="title class_">Promise</span>.<span class="title function_">reject</span>(<span class="string">&#x27;1&#x27;</span>).<span class="title function_">catch</span>(<span class="function">(<span class="params">err</span>) =&gt;</span> &#123;</span><br><span class="line">        <span class="variable language_">console</span>.<span class="title function_">log</span>(err);</span><br><span class="line">    &#125;);</span><br><span class="line">&#125;</span><br><span class="line"><span class="title function_">myFunction</span>(); <span class="comment">// 1</span></span><br></pre></td></tr></table></figure>
<h4 id="js中的解构赋值"><a href="#js中的解构赋值" class="headerlink" title="js中的解构赋值"></a>js中的解构赋值</h4><p><strong>解构赋值</strong>语法是一种JavaScript表达式。通过 <strong>解构赋值</strong>，可以将属性/值从对象/数组中取出，来赋值给其他的变量。</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://wrr123.github.io/2020/08/04/oracle%E8%A1%A8%E5%AD%97%E6%AE%B5%E8%BD%AC%E6%88%90jqGrid%E7%9A%84colModel/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="田园隐士">
      <meta itemprop="description" content="talk is cheap, show me the code">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一缕烟气">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2020/08/04/oracle%E8%A1%A8%E5%AD%97%E6%AE%B5%E8%BD%AC%E6%88%90jqGrid%E7%9A%84colModel/" class="post-title-link" itemprop="url">oracle表字段转成jqGrid的colModel</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-08-04 17:28:27" itemprop="dateCreated datePublished" datetime="2020-08-04T17:28:27+08:00">2020-08-04</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2022-02-18 10:52:04" itemprop="dateModified" datetime="2022-02-18T10:52:04+08:00">2022-02-18</time>
              </span>

          <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>431</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>1 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h5 id="利用sql将表中的字段一次性转换成jqGrid的colModel"><a href="#利用sql将表中的字段一次性转换成jqGrid的colModel" class="headerlink" title="利用sql将表中的字段一次性转换成jqGrid的colModel"></a>利用sql将表中的字段一次性转换成jqGrid的colModel</h5><p><u>一个例子</u></p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> </span><br><span class="line"><span class="built_in">listagg</span>(<span class="string">&#x27;&#123; label: &#x27;&#x27;&#x27;</span><span class="operator">||</span>t.COMMENTS<span class="operator">||</span><span class="string">&#x27;&#x27;&#x27;, name: &#x27;&#x27;&#x27;</span><span class="operator">||</span><span class="built_in">lower</span>(t.COLUMN_NAME)<span class="operator">||</span><span class="string">&#x27;&#x27;&#x27;, index: &#x27;&#x27;&#x27;</span><span class="operator">||</span><span class="built_in">lower</span>(t.COLUMN_NAME)<span class="operator">||</span><span class="string">&#x27;&#x27;&#x27;, width: 10, align: &#x27;&#x27;center&#x27;&#x27; &#125;,&#x27;</span><span class="operator">||</span>chr(<span class="number">13</span>), <span class="string">&#x27;&#x27;</span>) <span class="keyword">within</span> <span class="keyword">group</span>(<span class="keyword">order</span> <span class="keyword">by</span> t.COLUMN_NAME <span class="keyword">desc</span>)</span><br><span class="line"><span class="keyword">from</span> all_col_comments t <span class="keyword">where</span> t.TABLE_NAME <span class="operator">=</span> <span class="string">&#x27;TEMP01&#x27;</span>;</span><br></pre></td></tr></table></figure>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://wrr123.github.io/2020/08/04/spring%E4%B8%AD-RequestBody%E5%92%8C-ReuqestParam%E7%9A%84%E5%8C%BA%E5%88%AB/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="田园隐士">
      <meta itemprop="description" content="talk is cheap, show me the code">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一缕烟气">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2020/08/04/spring%E4%B8%AD-RequestBody%E5%92%8C-ReuqestParam%E7%9A%84%E5%8C%BA%E5%88%AB/" class="post-title-link" itemprop="url">spring中@RequestBody和@ReuqestParam的区别</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-08-04 15:36:08" itemprop="dateCreated datePublished" datetime="2020-08-04T15:36:08+08:00">2020-08-04</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2022-02-18 10:52:04" itemprop="dateModified" datetime="2022-02-18T10:52:04+08:00">2022-02-18</time>
              </span>

          <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>951</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>1 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h5 id="RequestParam"><a href="#RequestParam" class="headerlink" title="@RequestParam"></a>@RequestParam</h5><ul>
<li>常用来处理简单类型的数据绑定，因为使用<code>request.getParameter()</code>的方式获取参数，所以可以处理get方式中queryString的值，也可以处理post方式中body data的值。</li>
<li>用来处理Content-Type为<code>application/x-www-form-urlencoded</code>编码的内容，提交方式为get、post。</li>
</ul>
<h5 id="RequestBody"><a href="#RequestBody" class="headerlink" title="@RequestBody"></a>@RequestBody</h5><ul>
<li>该注解常用来处理Content-Type: 不是<code>application/x-www-form-urlencoded</code>编码的内容，例如application/json, application/xml等。</li>
<li>SpringMVC通过使用HandlerAdapter 配置的HttpMessageConverters来解析HttpEntity中的数据，然后绑定到相应的bean上。</li>
</ul>
<h5 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h5><ol>
<li><blockquote>
<p>在GET请求中，不能使用@RequestBody。</p>
</blockquote>
</li>
<li><blockquote>
<p>在POST请求，可以使用@RequestBody和@RequestParam，但是如果使用@RequestBody，对于参数转化的配置必须统一。</p>
</blockquote>
</li>
</ol>
<h5 id="ajax传递json格式参数，后端使用-RequestBody来接收"><a href="#ajax传递json格式参数，后端使用-RequestBody来接收" class="headerlink" title="ajax传递json格式参数，后端使用@RequestBody来接收"></a>ajax传递json格式参数，后端使用<code>@RequestBody</code>来接收</h5><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">function</span> <span class="title function_">icheckDelete</span>(<span class="params">url</span>)&#123;</span><br><span class="line">    <span class="keyword">var</span> parms = &#123;</span><br><span class="line">        list : array <span class="comment">//这是个数组</span></span><br><span class="line">    &#125;;</span><br><span class="line"></span><br><span class="line">    $.<span class="title function_">ajax</span>(&#123;</span><br><span class="line">        <span class="attr">dataType</span>: <span class="string">&quot;JSON&quot;</span>,</span><br><span class="line">        <span class="attr">contentType</span>:<span class="string">&#x27;application/json;charset=UTF-8&#x27;</span>,<span class="comment">//关键是要加上这行</span></span><br><span class="line">        <span class="attr">traditional</span>:<span class="literal">true</span>,<span class="comment">//这使json格式的字符不会被转码</span></span><br><span class="line">        <span class="attr">data</span>: <span class="title class_">JSON</span>.<span class="title function_">stringify</span>(parms),</span><br><span class="line">        <span class="attr">type</span>: <span class="string">&quot;DELETE&quot;</span>, </span><br><span class="line">        <span class="attr">timeout</span>: <span class="number">20000</span>,</span><br><span class="line">        <span class="attr">url</span>: url,</span><br><span class="line">        success : <span class="keyword">function</span> (<span class="params"></span>) &#123;</span><br><span class="line">            <span class="title function_">alert</span>(<span class="string">&quot;删除成功！&quot;</span>);</span><br><span class="line">        &#125;,</span><br><span class="line">        error : <span class="keyword">function</span> (<span class="params">data</span>)&#123;</span><br><span class="line">            <span class="title function_">alert</span>(data.<span class="property">responseText</span>);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;);</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://wrr123.github.io/2020/08/04/oracle%E8%A1%A82java%E5%AE%9E%E4%BD%93%E7%B1%BB/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="田园隐士">
      <meta itemprop="description" content="talk is cheap, show me the code">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一缕烟气">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2020/08/04/oracle%E8%A1%A82java%E5%AE%9E%E4%BD%93%E7%B1%BB/" class="post-title-link" itemprop="url">oracle表2java实体类</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-08-04 09:44:36" itemprop="dateCreated datePublished" datetime="2020-08-04T09:44:36+08:00">2020-08-04</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2022-02-18 10:52:04" itemprop="dateModified" datetime="2022-02-18T10:52:04+08:00">2022-02-18</time>
              </span>

          <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>2.3k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>2 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h4 id="将oracle中的表转为java实体类"><a href="#将oracle中的表转为java实体类" class="headerlink" title="将oracle中的表转为java实体类"></a>将oracle中的表转为java实体类</h4><ul>
<li>swagger实体类注解<code>@ApiModelProperty</code></li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> </span><br><span class="line"><span class="built_in">listagg</span>(<span class="string">&#x27;@ApiModelProperty(&quot;&#x27;</span><span class="operator">||</span>t.COMMENTS<span class="operator">||</span><span class="string">&#x27;&quot;)&#x27;</span><span class="operator">||</span>chr(<span class="number">13</span>)<span class="operator">||</span><span class="string">&#x27;private String &#x27;</span><span class="operator">||</span><span class="built_in">lower</span>(t.COLUMN_NAME)<span class="operator">||</span><span class="string">&#x27;;&#x27;</span><span class="operator">||</span>chr(<span class="number">13</span>)<span class="operator">||</span>chr(<span class="number">13</span>), <span class="string">&#x27;&#x27;</span>) <span class="keyword">within</span> <span class="keyword">group</span>(<span class="keyword">order</span> <span class="keyword">by</span> t.COLUMN_NAME)</span><br><span class="line"><span class="keyword">from</span> all_col_comments t <span class="keyword">where</span> t.TABLE_NAME <span class="operator">=</span> <span class="string">&#x27;TEMP01&#x27;</span>;</span><br></pre></td></tr></table></figure>
<p>​    <u><em>listagg函数可以使用wm_concat函数来替换</em></u></p>
<h4 id="oracle中一些特殊符号的转换"><a href="#oracle中一些特殊符号的转换" class="headerlink" title="oracle中一些特殊符号的转换"></a>oracle中一些特殊符号的转换</h4><div class="table-container">
<table>
<thead>
<tr>
<th>说明</th>
<th>转换</th>
</tr>
</thead>
<tbody>
<tr>
<td>制表符</td>
<td>chr(9)</td>
</tr>
<tr>
<td>换行符</td>
<td>chr(10)</td>
</tr>
<tr>
<td>回车符</td>
<td>chr(13)</td>
</tr>
</tbody>
</table>
</div>
<h4 id="oracle和java的数据类型对应关系"><a href="#oracle和java的数据类型对应关系" class="headerlink" title="oracle和java的数据类型对应关系"></a>oracle和java的数据类型对应关系</h4><div class="table-container">
<table>
<thead>
<tr>
<th style="text-align:left">SQL数据类型</th>
<th style="text-align:left">JDBC类型代码</th>
<th style="text-align:left">标准的Java类型</th>
<th style="text-align:left">Oracle扩展的Java类型</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left"></td>
<td style="text-align:left">1.0标准的JDBC类型:</td>
<td style="text-align:left"></td>
<td style="text-align:left"></td>
</tr>
<tr>
<td style="text-align:left"><code>CHAR</code></td>
<td style="text-align:left"><code>java.sql.Types.CHAR</code></td>
<td style="text-align:left"><code>java.lang.String</code></td>
<td style="text-align:left"><code>oracle.sql.CHAR</code></td>
</tr>
<tr>
<td style="text-align:left"><code>VARCHAR2</code></td>
<td style="text-align:left"><code>java.sql.Types.VARCHAR</code></td>
<td style="text-align:left"><code>java.lang.String</code></td>
<td style="text-align:left"><code>oracle.sql.CHAR</code></td>
</tr>
<tr>
<td style="text-align:left"><code>LONG</code></td>
<td style="text-align:left"><code>java.sql.Types.LONGVARCHAR</code></td>
<td style="text-align:left"><code>java.lang.String</code></td>
<td style="text-align:left"><code>oracle.sql.CHAR</code></td>
</tr>
<tr>
<td style="text-align:left"><code>NUMBER</code></td>
<td style="text-align:left"><code>java.sql.Types.NUMERIC</code></td>
<td style="text-align:left"><code>java.math.BigDecimal</code></td>
<td style="text-align:left"><code>oracle.sql.NUMBER</code></td>
</tr>
<tr>
<td style="text-align:left"><code>NUMBER</code></td>
<td style="text-align:left"><code>java.sql.Types.DECIMAL</code></td>
<td style="text-align:left"><code>java.math.BigDecimal</code></td>
<td style="text-align:left"><code>oracle.sql.NUMBER</code></td>
</tr>
<tr>
<td style="text-align:left"><code>NUMBER</code></td>
<td style="text-align:left"><code>java.sql.Types.BIT</code></td>
<td style="text-align:left"><code>boolean</code></td>
<td style="text-align:left"><code>oracle.sql.NUMBER</code></td>
</tr>
<tr>
<td style="text-align:left"><code>NUMBER</code></td>
<td style="text-align:left"><code>java.sql.Types.TINYINT</code></td>
<td style="text-align:left"><code>byte</code></td>
<td style="text-align:left"><code>oracle.sql.NUMBER</code></td>
</tr>
<tr>
<td style="text-align:left"><code>NUMBER</code></td>
<td style="text-align:left"><code>java.sql.Types.SMALLINT</code></td>
<td style="text-align:left"><code>short</code></td>
<td style="text-align:left"><code>oracle.sql.NUMBER</code></td>
</tr>
<tr>
<td style="text-align:left"><code>NUMBER</code></td>
<td style="text-align:left"><code>java.sql.Types.INTEGER</code></td>
<td style="text-align:left"><code>int</code></td>
<td style="text-align:left"><code>oracle.sql.NUMBER</code></td>
</tr>
<tr>
<td style="text-align:left"><code>NUMBER</code></td>
<td style="text-align:left"><code>java.sql.Types.BIGINT</code></td>
<td style="text-align:left"><code>long</code></td>
<td style="text-align:left"><code>oracle.sql.NUMBER</code></td>
</tr>
<tr>
<td style="text-align:left"><code>NUMBER</code></td>
<td style="text-align:left"><code>java.sql.Types.REAL</code></td>
<td style="text-align:left"><code>float</code></td>
<td style="text-align:left"><code>oracle.sql.NUMBER</code></td>
</tr>
<tr>
<td style="text-align:left"><code>NUMBER</code></td>
<td style="text-align:left"><code>java.sql.Types.FLOAT</code></td>
<td style="text-align:left"><code>double</code></td>
<td style="text-align:left"><code>oracle.sql.NUMBER</code></td>
</tr>
<tr>
<td style="text-align:left"><code>NUMBER</code></td>
<td style="text-align:left"><code>java.sql.Types.DOUBLE</code></td>
<td style="text-align:left"><code>double</code></td>
<td style="text-align:left"><code>oracle.sql.NUMBER</code></td>
</tr>
<tr>
<td style="text-align:left"><code>RAW</code></td>
<td style="text-align:left"><code>java.sql.Types.BINARY</code></td>
<td style="text-align:left"><code>byte[]</code></td>
<td style="text-align:left"><code>oracle.sql.RAW</code></td>
</tr>
<tr>
<td style="text-align:left"><code>RAW</code></td>
<td style="text-align:left"><code>java.sql.Types.VARBINARY</code></td>
<td style="text-align:left"><code>byte[]</code></td>
<td style="text-align:left"><code>oracle.sql.RAW</code></td>
</tr>
<tr>
<td style="text-align:left"><code>LONGRAW</code></td>
<td style="text-align:left"><code>java.sql.Types.LONGVARBINARY</code></td>
<td style="text-align:left"><code>byte[]</code></td>
<td style="text-align:left"><code>oracle.sql.RAW</code></td>
</tr>
<tr>
<td style="text-align:left"><code>DATE</code></td>
<td style="text-align:left"><code>java.sql.Types.DATE</code></td>
<td style="text-align:left"><code>java.sql.Date</code></td>
<td style="text-align:left"><code>oracle.sql.DATE</code></td>
</tr>
<tr>
<td style="text-align:left"><code>DATE</code></td>
<td style="text-align:left"><code>java.sql.Types.TIME</code></td>
<td style="text-align:left"><code>java.sql.Time</code></td>
<td style="text-align:left"><code>oracle.sql.DATE</code></td>
</tr>
<tr>
<td style="text-align:left"><code>TIMESTAMP</code></td>
<td style="text-align:left"><code>java.sql.Types.TIMESTAMP</code></td>
<td style="text-align:left"><code>javal.sql.Timestamp</code></td>
<td style="text-align:left"><code>oracle.sql.TIMESTAMP</code></td>
</tr>
<tr>
<td style="text-align:left"></td>
<td style="text-align:left">2.0标准的JDBC类型:</td>
<td style="text-align:left"></td>
<td style="text-align:left"></td>
</tr>
<tr>
<td style="text-align:left"><code>BLOB</code></td>
<td style="text-align:left"><code>java.sql.Types.BLOB</code></td>
<td style="text-align:left"><code>java.sql.Blob</code></td>
<td style="text-align:left"><code>oracle.sql.BLOB</code></td>
</tr>
<tr>
<td style="text-align:left"><code>CLOB</code></td>
<td style="text-align:left"><code>java.sql.Types.CLOB</code></td>
<td style="text-align:left"><code>java.sql.Clob</code></td>
<td style="text-align:left"><code>oracle.sql.CLOB</code></td>
</tr>
<tr>
<td style="text-align:left">用户定义的对象</td>
<td style="text-align:left"><code>java.sql.Types.STRUCT</code></td>
<td style="text-align:left"><code>java.sql.Struct</code></td>
<td style="text-align:left"><code>oracle.sql.STRUCT</code></td>
</tr>
<tr>
<td style="text-align:left">用户定义的参考</td>
<td style="text-align:left"><code>java.sql.Types.REF</code></td>
<td style="text-align:left"><code>java.sql.Ref</code></td>
<td style="text-align:left"><code>oracle.sql.REF</code></td>
</tr>
<tr>
<td style="text-align:left">用户定义的集合</td>
<td style="text-align:left"><code>java.sql.Types.ARRAY</code></td>
<td style="text-align:left"><code>java.sql.Array</code></td>
<td style="text-align:left"><code>oracle.sql.ARRAY</code></td>
</tr>
<tr>
<td style="text-align:left"></td>
<td style="text-align:left">Oracle扩展:</td>
<td style="text-align:left"></td>
<td style="text-align:left"></td>
</tr>
<tr>
<td style="text-align:left"><code>BFILE</code></td>
<td style="text-align:left"><code>oracle.jdbc.OracleTypes.BFILE</code></td>
<td style="text-align:left">N/A</td>
<td style="text-align:left"><code>oracle.sql.BFILE</code></td>
</tr>
<tr>
<td style="text-align:left"><code>ROWID</code></td>
<td style="text-align:left"><code>oracle.jdbc.OracleTypes.ROWID</code></td>
<td style="text-align:left">N/A</td>
<td style="text-align:left"><code>oracle.sql.ROWID</code></td>
</tr>
<tr>
<td style="text-align:left"><code>REF CURSOR</code></td>
<td style="text-align:left"><code>oracle.jdbc.OracleTypes.CURSOR</code></td>
<td style="text-align:left"><code>java.sql.ResultSet</code></td>
<td style="text-align:left"><code>oracle.jdbc.OracleResultSet</code></td>
</tr>
<tr>
<td style="text-align:left"><code>TIMESTAMP</code></td>
<td style="text-align:left"><code>oracle.jdbc.OracleTypes.TIMESTAMP</code></td>
<td style="text-align:left"><code>java.sql.Timestamp</code></td>
<td style="text-align:left"><code>oracle.sql.TIMESTAMP</code></td>
</tr>
<tr>
<td style="text-align:left"><code>TIMESTAMP WITH TIME ZONE</code></td>
<td style="text-align:left"><code>oracle.jdbc.OracleTypes.TIMESTAMPTZ</code></td>
<td style="text-align:left"><code>java.sql.Timestamp</code></td>
<td style="text-align:left"><code>oracle.sql.TIMESTAMPTZ</code></td>
</tr>
<tr>
<td style="text-align:left"><code>TIMESTAMP WITH LOCAL TIME ZONE</code></td>
<td style="text-align:left"><code>oracle.jdbc.OracleTypes.TIMESTAMPLTZ</code></td>
<td style="text-align:left"><code>java.sql.Timestamp</code></td>
<td style="text-align:left"><code>oracle.sql.TIMESTAMPLTZ</code></td>
</tr>
</tbody>
</table>
</div>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://wrr123.github.io/2020/08/03/spring-boot%E8%BF%9E%E6%8E%A5sqlserver/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="田园隐士">
      <meta itemprop="description" content="talk is cheap, show me the code">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一缕烟气">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2020/08/03/spring-boot%E8%BF%9E%E6%8E%A5sqlserver/" class="post-title-link" itemprop="url">spring-boot连接sqlserver</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-08-03 16:24:28" itemprop="dateCreated datePublished" datetime="2020-08-03T16:24:28+08:00">2020-08-03</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2022-02-18 10:52:04" itemprop="dateModified" datetime="2022-02-18T10:52:04+08:00">2022-02-18</time>
              </span>

          <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>1.6k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>1 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h5 id="下载所需依赖的jar包"><a href="#下载所需依赖的jar包" class="headerlink" title="下载所需依赖的jar包"></a>下载所需依赖的jar包</h5><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>com.microsoft.sqlserver<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>sqljdbc4<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">scope</span>&gt;</span>4.0<span class="tag">&lt;/<span class="name">scope</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">version</span>&gt;</span>4.0<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h5 id="配置数据源"><a href="#配置数据源" class="headerlink" title="配置数据源"></a>配置数据源</h5><figure class="highlight properties"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring.datasource.url</span>=<span class="string">jdbc:sqlserver://localhost:1433;DatabaseName=数据库名</span></span><br><span class="line"><span class="attr">spring.datasource.driverClassName</span>=<span class="string">com.microsoft.sqlserver.jdbc.SQLServerDriver</span></span><br><span class="line"><span class="attr">spring.datasource.username</span>=<span class="string">用户名</span></span><br><span class="line"><span class="attr">spring.datasource.password</span>=<span class="string">密码</span></span><br></pre></td></tr></table></figure>
<h5 id="sqlserver查看表机构"><a href="#sqlserver查看表机构" class="headerlink" title="sqlserver查看表机构"></a>sqlserver查看表机构</h5><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">sp_help table_name;           </span><br><span class="line">sp_columns table_name;</span><br></pre></td></tr></table></figure>
<h5 id="sqlserver查看表的主键约束"><a href="#sqlserver查看表的主键约束" class="headerlink" title="sqlserver查看表的主键约束"></a>sqlserver查看表的主键约束</h5><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sp_helpconstraint table_name;</span><br></pre></td></tr></table></figure>
<h5 id="sqlserver查看表字段注释"><a href="#sqlserver查看表字段注释" class="headerlink" title="sqlserver查看表字段注释"></a>sqlserver查看表字段注释</h5><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span></span><br><span class="line">c.name <span class="keyword">as</span> columnName,</span><br><span class="line">a.VALUE <span class="keyword">as</span> columnDescript</span><br><span class="line"><span class="keyword">FROM</span></span><br><span class="line">sys.extended_properties a,</span><br><span class="line">sysobjects b,</span><br><span class="line">sys.columns c</span><br><span class="line"><span class="keyword">WHERE</span></span><br><span class="line">a.major_id <span class="operator">=</span> b.id</span><br><span class="line"><span class="keyword">AND</span> c.object_id <span class="operator">=</span> b.id</span><br><span class="line"><span class="keyword">AND</span> c.column_id <span class="operator">=</span> a.minor_id</span><br><span class="line"><span class="keyword">AND</span> b.name <span class="operator">=</span> ‘要查询的表名’</span><br></pre></td></tr></table></figure>
<h5 id="字段对应关系"><a href="#字段对应关系" class="headerlink" title="字段对应关系"></a>字段对应关系</h5><div class="table-container">
<table>
<thead>
<tr>
<th>SQL Server 类型</th>
<th>JDBC 类型 (java.sql.Types)</th>
<th>Java 语言类型</th>
</tr>
</thead>
<tbody>
<tr>
<td>bigint</td>
<td>BIGINT</td>
<td>long</td>
</tr>
<tr>
<td>timestampbinary</td>
<td>BINARY</td>
<td>byte[]</td>
</tr>
<tr>
<td>bit</td>
<td>BIT</td>
<td>boolean</td>
</tr>
<tr>
<td>char</td>
<td>CHAR</td>
<td>String</td>
</tr>
<tr>
<td>decimalmoneysmallmoney</td>
<td>DECIMAL</td>
<td>java.math.BigDecimal</td>
</tr>
<tr>
<td>float</td>
<td>DOUBLE</td>
<td>double</td>
</tr>
<tr>
<td>int</td>
<td>INTEGER</td>
<td>int</td>
</tr>
<tr>
<td>imagevarbinary(max)</td>
<td>LONGVARBINARY</td>
<td>byte[]</td>
</tr>
<tr>
<td>varchar(max)text</td>
<td>LONGVARCHAR</td>
<td>String</td>
</tr>
<tr>
<td>nchar</td>
<td>CHARNCHAR (Java SE 6.0)</td>
<td>String</td>
</tr>
<tr>
<td>nvarchar</td>
<td>VARCHARNVARCHAR (Java SE 6.0)</td>
<td>String</td>
</tr>
<tr>
<td>nvarchar(max)ntext</td>
<td>LONGVARCHARLONGNVARCHAR (Java SE 6.0)</td>
<td>String</td>
</tr>
<tr>
<td>numeric</td>
<td>NUMERIC</td>
<td>java.math.BigDecimal</td>
</tr>
<tr>
<td>real</td>
<td>REAL</td>
<td>float</td>
</tr>
<tr>
<td>smallint</td>
<td>SMALLINT</td>
<td>short</td>
</tr>
<tr>
<td>datetimesmalldatetime</td>
<td>TIMESTAMP</td>
<td>java.sql.Timestamp</td>
</tr>
<tr>
<td>varbinaryudt</td>
<td>VARBINARY</td>
<td>byte[]</td>
</tr>
<tr>
<td>varchar</td>
<td>VARCHAR</td>
<td>String</td>
</tr>
<tr>
<td>tinyint</td>
<td>TINYINT</td>
<td>short</td>
</tr>
<tr>
<td>uniqueidentifier</td>
<td>CHAR</td>
<td>String</td>
</tr>
<tr>
<td>xml</td>
<td>LONGVARCHARSQLXML (Java SE 6.0)</td>
<td>StringSQLXML</td>
</tr>
<tr>
<td>time</td>
<td>TIME (1)</td>
<td>java.sql.Time (1)</td>
</tr>
<tr>
<td>date</td>
<td>DATE</td>
<td>java.sql.Date</td>
</tr>
<tr>
<td>datetime2</td>
<td>TIMESTAMP</td>
<td>java.sql.Timestamp</td>
</tr>
<tr>
<td>datetimeoffset (2)</td>
<td>microsoft.sql.Types.DATETIMEOFFSET</td>
<td>microsoft.sql.DateTimeOffset</td>
</tr>
</tbody>
</table>
</div>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://wrr123.github.io/2020/08/03/swagger%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="田园隐士">
      <meta itemprop="description" content="talk is cheap, show me the code">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一缕烟气">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2020/08/03/swagger%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8/" class="post-title-link" itemprop="url">swagger基本使用</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-08-03 10:19:23" itemprop="dateCreated datePublished" datetime="2020-08-03T10:19:23+08:00">2020-08-03</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2022-02-18 10:52:04" itemprop="dateModified" datetime="2022-02-18T10:52:04+08:00">2022-02-18</time>
              </span>

          <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>5.8k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>5 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h4 id="定义"><a href="#定义" class="headerlink" title="定义"></a>定义</h4><p>一种接口文档的规范</p>
<h4 id="简介"><a href="#简介" class="headerlink" title="简介"></a>简介</h4><p>是一套基于<code>OpenAPI</code>规范构建的开源工具，可以帮助我们设计、构建、记录以及使用<code>RestAPI</code>。swagger主要包含了以下三个方面：</p>
<ol>
<li>Swagger Editor：基于浏览器的编辑器，我们可以使用它编写我们的<code>OpenAPI</code>规范。</li>
<li>Swagger UI: 它会将我们编写的<code>OpenAPI</code>规范呈现为交互式的API文档。</li>
<li>Swagger Codegen: 它可以通过<code>OpenAPI(以前称为Swagger)</code>规范定义的任何API生成服务器存根和客户端SDK来简化构建过程。</li>
</ol>
<h4 id="使用Swagger有什么优点"><a href="#使用Swagger有什么优点" class="headerlink" title="使用Swagger有什么优点"></a>使用Swagger有什么优点</h4><ol>
<li>代码变，文档变。只需要少量的注解，Swagger就可以根据代码自动生成API文档，很好的保证了文档的时效性。</li>
<li>跨语言性，支持40多种语言。</li>
<li>Swagger UI呈现出来的是一份可交互式的API文档，我们可以直接在文档页面尝试API的调用，省去了准备复杂的调用参数的过程。</li>
<li>还可以将文档规范导入相关的工具(例如<code>SnopUI</code>),这些工具将会为我们自动的创建自动化测试。</li>
</ol>
<h4 id="基于spring-boot-web项目的基本使用"><a href="#基于spring-boot-web项目的基本使用" class="headerlink" title="基于spring boot web项目的基本使用"></a>基于spring boot web项目的基本使用</h4><h5 id="添加依赖"><a href="#添加依赖" class="headerlink" title="添加依赖"></a>添加依赖</h5><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.boot<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-starter-web<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h5 id="编写接口"><a href="#编写接口" class="headerlink" title="编写接口"></a>编写接口</h5><ol>
<li>首先我们创建三个包：<code>cn.itweknow.sbswagger.controller</code>、<code>cn.itweknow.sbswagger.testcontroller</code> 以及 <code>cn.itweknow.sbswagger.model</code>。</li>
<li>在 controller 包下新建 <code>UserController.java</code> 类，在 <code>testcontroller</code> 包下新建 <code>TestController.java</code> 类，在 model 包下新建 <code>User.java</code> 类。</li>
<li><code>UserController</code> 提供用户的增、删、改、查四个接口，<code>TestContrller</code> 提供一个测试接口，这里粘上 <code>UserController.java</code> 的代码，其余代码可以查看<a target="_blank" rel="noopener" href="https://github.com/ganchaoyang/spring-tutorial/tree/master/sb-swagger">源码</a> 。</li>
</ol>
<p>UserController.java代码如下</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@RestController</span></span><br><span class="line"><span class="meta">@RequestMapping(&quot;/user&quot;)</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">UserController</span> &#123;</span><br><span class="line">    <span class="meta">@PostMapping(&quot;/add&quot;)</span></span><br><span class="line">    <span class="keyword">public</span> <span class="type">boolean</span> <span class="title function_">addUser</span><span class="params">(<span class="meta">@RequestBody</span> User user)</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="meta">@GetMapping(&quot;/find/&#123;id&#125;&quot;)</span></span><br><span class="line">    <span class="keyword">public</span> User <span class="title function_">findById</span><span class="params">(<span class="meta">@PathVariable(&quot;id&quot;)</span> <span class="type">int</span> id)</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> <span class="title class_">User</span>();</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="meta">@PutMapping(&quot;/update&quot;)</span></span><br><span class="line">    <span class="keyword">public</span> <span class="type">boolean</span> <span class="title function_">update</span><span class="params">(<span class="meta">@RequestBody</span> User user)</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">    &#125;</span><br><span class="line">     <span class="meta">@DeleteMapping(&quot;/delete/&#123;id&#125;&quot;)</span></span><br><span class="line">    <span class="keyword">public</span> <span class="type">boolean</span> <span class="title function_">delete</span><span class="params">(<span class="meta">@PathVariable(&quot;id&quot;)</span> <span class="type">int</span> id)</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h5 id="集成Swagger2"><a href="#集成Swagger2" class="headerlink" title="集成Swagger2"></a>集成Swagger2</h5><p>上面的java类已经具有了如下的几个接口</p>
<ol>
<li>/user/add：新增用户。</li>
<li>/user/find/{id}：根据 id 查询用户。</li>
<li>/user/update：更新用户。</li>
<li>/user/delete/{id}：根据 id 删除用户。</li>
</ol>
<h6 id="添加swagger依赖"><a href="#添加swagger依赖" class="headerlink" title="添加swagger依赖"></a>添加swagger依赖</h6><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>io.springfox<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>springfox-swagger2<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">version</span>&gt;</span>2.9.2<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h6 id="java配置"><a href="#java配置" class="headerlink" title="java配置"></a>java配置</h6><p>添加如下的类</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Configuration</span></span><br><span class="line"><span class="meta">@EnableSwagger2</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">SwaggerConfig</span> &#123;</span><br><span class="line">    <span class="meta">@Bean</span></span><br><span class="line">    <span class="keyword">public</span> Docket <span class="title function_">api</span><span class="params">()</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> <span class="title class_">Docket</span>(DocumentationType.SWAGGER_2)</span><br><span class="line">                .select()</span><br><span class="line">                .apis(RequestHandlerSelectors.any())</span><br><span class="line">                .paths(PathSelectors.any())</span><br><span class="line">                .build();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><strong>注意: <code>@Configuration</code> 是告诉 Spring Boot 需要加载这个配置类， <code>@EnableSwagger2</code> 是启用 Swagger2，如果没加的话自然而然也就看不到后面的验证效果了</strong></p>
<h6 id="验证"><a href="#验证" class="headerlink" title="验证"></a>验证</h6><blockquote>
<p>至此，我们已经成功的在 Spring Boot 项目中集成了 Swagger2，启动项目后，我们可以通过在浏览器中访问 <code>http://localhost:8080/v2/api-docs</code> 来验证，您会发现返回的结果是一段 JSON 串，可读性非常差。幸运的是 Swagger2 为我们提供了可视化的交互界面 SwaggerUI，下面我们就一起来试试吧。</p>
</blockquote>
<h5 id="集成Swagger-UI"><a href="#集成Swagger-UI" class="headerlink" title="集成Swagger UI"></a>集成Swagger UI</h5><h6 id="添加依赖-1"><a href="#添加依赖-1" class="headerlink" title="添加依赖"></a>添加依赖</h6><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>io.springfox<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>springfox-swagger-ui<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">version</span>&gt;</span>2.9.2<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h6 id="访问验证"><a href="#访问验证" class="headerlink" title="访问验证"></a>访问验证</h6><blockquote>
<p>其实就只需要添加一下依赖就可以了，我们重新启动一下项目，然后在浏览器中访问 <code>http://localhost:8080/swagger-ui.html</code> 就可以看到如下的效果了:</p>
</blockquote>
<p><img src="http://localhost:4000/2020/08/03/swagger%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8/001.png" alt></p>
<h4 id="高级配置"><a href="#高级配置" class="headerlink" title="高级配置"></a>高级配置</h4><h5 id="文档相关描述配置"><a href="#文档相关描述配置" class="headerlink" title="文档相关描述配置"></a>文档相关描述配置</h5><ol>
<li><p>通过在控制器类上增加<code>@Api</code>注解，可以给控制器增加描述和标签信息。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Api(tags = &quot;用户相关接口&quot;, description = &quot;提供用户相关的 Rest API&quot;)</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">UserController</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>通过在接口方法上增加<code>@ApiOperation</code>注解来展开对接口的描述，当然这个注解还可以指定很多的内容</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@ApiOperation(&quot;新增用户接口&quot;)</span></span><br><span class="line"><span class="meta">@PostMapping(&quot;/add&quot;)</span></span><br><span class="line"><span class="keyword">public</span> <span class="type">boolean</span> <span class="title function_">addUser</span><span class="params">(<span class="meta">@RequestBody</span> User user)</span> &#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>实体描述，可以通过<code>@ApiModel</code>和<code>@ApiModelProperty</code>注解来对我们API中所涉及到的对象进行描述。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@ApiModel(&quot;用户实体&quot;)</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">User</span> &#123;</span><br><span class="line">    <span class="meta">@ApiModelProperty(&quot;用户 id&quot;)</span></span><br><span class="line"><span class="keyword">private</span> <span class="type">int</span> id;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><blockquote>
<p>文档信息配置，Swagger 还支持设置一些文档的版本号、联系人邮箱、网站、版权、开源协议等等信息，但与上面几条不同的是这些信息不是通过注解配置，而是通过创建一个 ApiInfo 对象，并且使用 <code>Docket.appInfo()</code> 方法来设置，我们在 SwaggerConfig.java 类中新增如下内容即可。</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Bean</span></span><br><span class="line"><span class="keyword">public</span> Docket <span class="title function_">api</span><span class="params">()</span> &#123;</span><br><span class="line"><span class="keyword">return</span> <span class="keyword">new</span> <span class="title class_">Docket</span>(DocumentationType.SWAGGER_2)</span><br><span class="line">.select()</span><br><span class="line">            .apis(RequestHandlerSelectors.any())</span><br><span class="line">            .paths(PathSelectors.any())</span><br><span class="line">            .build()</span><br><span class="line">            .apiInfo(apiInfo());</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">private</span> ApiInfo <span class="title function_">apiInfo</span><span class="params">()</span> &#123;</span><br><span class="line"><span class="keyword">return</span> <span class="keyword">new</span> <span class="title class_">ApiInfo</span>(</span><br><span class="line">            <span class="string">&quot;Spring Boot 项目集成 Swagger 实例文档&quot;</span>,</span><br><span class="line">            <span class="string">&quot;我的博客网站：https://itweknow.cn，欢迎大家访问。&quot;</span>,</span><br><span class="line">            <span class="string">&quot;API V1.0&quot;</span>,</span><br><span class="line">            <span class="string">&quot;Terms of service&quot;</span>,</span><br><span class="line">            <span class="keyword">new</span> <span class="title class_">Contact</span>(<span class="string">&quot;名字想好没&quot;</span>, <span class="string">&quot;https://itweknow.cn&quot;</span>, <span class="string">&quot;gancy.programmer@gmail.com&quot;</span>),</span><br><span class="line">                <span class="string">&quot;Apache&quot;</span>, <span class="string">&quot;http://www.apache.org/&quot;</span>, Collections.emptyList());</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
</ol>
<p>补全信息后的swagger文档界面</p>
<p><img src="http://localhost:4000/2020/08/03/swagger%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8/002.png" alt></p>
<h4 id="接口过滤"><a href="#接口过滤" class="headerlink" title="接口过滤"></a>接口过滤</h4><blockquote>
<p>有些时候我们并不是希望所有的 Rest API 都呈现在文档上，这种情况下 Swagger2 提供给我们了两种方式配置，一种是基于 <code>@ApiIgnore</code> 注解，另一种是在 Docket 上增加筛选。</p>
</blockquote>
<ol>
<li><p><code>@ApiIgnore</code>注解</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@ApiIgnore</span></span><br><span class="line"><span class="keyword">public</span> <span class="type">boolean</span> <span class="title function_">delete</span><span class="params">(<span class="meta">@PathVariable(&quot;id&quot;)</span> <span class="type">int</span> id)</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>在 Docket 上增加筛选。Docket 类提供了 <code>apis()</code> 和 <code>paths()</code> 两个方法来帮助我们在不同级别上过滤接口：</p>
<ul>
<li><code>apis()</code> ：这种方式我们可以通过指定包名的方式，让 Swagger 只去某些包下面扫描。</li>
<li><code>paths()</code> ：这种方式可以通过筛选 API 的 url 来进行过滤。</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">.apis(RequestHandlerSelectors.basePackage(<span class="string">&quot;cn.itweknow.sbswagger.controller&quot;</span>))</span><br><span class="line">.paths(Predicates.or(PathSelectors.ant(<span class="string">&quot;/user/add&quot;</span>),</span><br><span class="line">        PathSelectors.ant(<span class="string">&quot;/user/find/*&quot;</span>)))</span><br></pre></td></tr></table></figure>
</li>
</ol>
<h4 id="自定义响应信息"><a href="#自定义响应信息" class="headerlink" title="自定义响应信息"></a>自定义响应信息</h4><blockquote>
<p>Swagger 允许我们通过 Docket 的 <code>globalResponseMessage()</code> 方法全局覆盖 HTTP 方法的响应消息，但是首先我们得通过 Docket 的 <code>useDefaultResponseMessages</code> 方法告诉 Swagger 不使用默认的 HTTP 响应消息，假设我们现在需要覆盖所有 GET 方法的 500 和 403 错误的响应消息，我们只需要在 SwaggerConfig.java 类中的 Docket Bean 下添加如下内容</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">.useDefaultResponseMessages(<span class="literal">false</span>)</span><br><span class="line">.globalResponseMessage(RequestMethod.GET, newArrayList(</span><br><span class="line"><span class="keyword">new</span> <span class="title class_">ResponseMessageBuilder</span>()</span><br><span class="line">              .code(<span class="number">500</span>)</span><br><span class="line">              .message(<span class="string">&quot;服务器发生异常&quot;</span>)</span><br><span class="line">              .responseModel(<span class="keyword">new</span> <span class="title class_">ModelRef</span>(<span class="string">&quot;Error&quot;</span>))</span><br><span class="line">              .build(),</span><br><span class="line">       <span class="keyword">new</span> <span class="title class_">ResponseMessageBuilder</span>()</span><br><span class="line">              .code(<span class="number">403</span>)</span><br><span class="line">              .message(<span class="string">&quot;资源不可用&quot;</span>)</span><br><span class="line">              .build()</span><br><span class="line">));</span><br></pre></td></tr></table></figure>
<h4 id="相关注解说明"><a href="#相关注解说明" class="headerlink" title="相关注解说明"></a>相关注解说明</h4><h5 id="Controller相关注解"><a href="#Controller相关注解" class="headerlink" title="Controller相关注解"></a>Controller相关注解</h5><p><code>@Api</code>: 可设置对控制器的描述。</p>
<div class="table-container">
<table>
<thead>
<tr>
<th style="text-align:left"><strong>注解属性</strong></th>
<th style="text-align:left"><strong>类型</strong></th>
<th style="text-align:left"><strong>描述</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">tags</td>
<td style="text-align:left">String[]</td>
<td style="text-align:left">控制器标签。</td>
</tr>
<tr>
<td style="text-align:left">description</td>
<td style="text-align:left">String</td>
<td style="text-align:left">控制器描述（该字段被申明为过期）。</td>
</tr>
</tbody>
</table>
</div>
<h5 id="接口相关注解"><a href="#接口相关注解" class="headerlink" title="接口相关注解"></a>接口相关注解</h5><p><code>@ApiOperation</code>: 可设置对接口的描述。</p>
<div class="table-container">
<table>
<thead>
<tr>
<th style="text-align:left"><strong>注解属性</strong></th>
<th style="text-align:left"><strong>类型</strong></th>
<th style="text-align:left"><strong>描述</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">value</td>
<td style="text-align:left">String</td>
<td style="text-align:left">接口说明。</td>
</tr>
<tr>
<td style="text-align:left">notes</td>
<td style="text-align:left">String</td>
<td style="text-align:left">接口发布说明。</td>
</tr>
<tr>
<td style="text-align:left">tags</td>
<td style="text-align:left">Stirng[]</td>
<td style="text-align:left">标签。</td>
</tr>
<tr>
<td style="text-align:left">response</td>
<td style="text-align:left">Class&lt;?&gt;</td>
<td style="text-align:left">接口返回类型。</td>
</tr>
<tr>
<td style="text-align:left">httpMethod</td>
<td style="text-align:left">String</td>
<td style="text-align:left">接口请求方式。</td>
</tr>
</tbody>
</table>
</div>
<p><code>@ApiIgnore</code>: Swagger 文档不会显示拥有该注解的接口。 <code>@ApiImplicitParams</code>: 用于描述接口的非对象参数集。 <code>@ApiImplicitParam</code>: 用于描述接口的非对象参数，一般与 <code>@ApiImplicitParams</code> 组合使用。</p>
<p><strong>@ApiImplicitParam 主要属性</strong></p>
<div class="table-container">
<table>
<thead>
<tr>
<th style="text-align:left"><strong>注解属性</strong></th>
<th style="text-align:left"><strong>描述</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">paramType</td>
<td style="text-align:left">查询参数类型，实际上就是参数放在那里。取值：path：以地址的形式提交数据，根据 id 查询用户的接口就是这种形式传参；query：Query string 的方式传参；header：以流的形式提交；form：以 Form 表单的形式提交。</td>
</tr>
<tr>
<td style="text-align:left">dataType</td>
<td style="text-align:left">参数的数据类型。取值：Long 和 String</td>
</tr>
<tr>
<td style="text-align:left">name</td>
<td style="text-align:left">参数名字。</td>
</tr>
<tr>
<td style="text-align:left">value</td>
<td style="text-align:left">参数意义的描述。</td>
</tr>
<tr>
<td style="text-align:left">required</td>
<td style="text-align:left">是否必填。取值：true：必填参数；false：非必填参数。</td>
</tr>
</tbody>
</table>
</div>
<h5 id="Model相关注解"><a href="#Model相关注解" class="headerlink" title="Model相关注解"></a>Model相关注解</h5><p><code>@ApiModel</code>: 可设置接口相关实体的描述。 <code>@ApiModelProperty</code>: 可设置实体属性的相关描述。</p>
<p><strong>@ApiModelProperty 主要属性</strong></p>
<div class="table-container">
<table>
<thead>
<tr>
<th style="text-align:left"><strong>注解属性</strong></th>
<th style="text-align:left"><strong>类型</strong></th>
<th style="text-align:left"><strong>描述</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">value</td>
<td style="text-align:left">String</td>
<td style="text-align:left">字段说明。</td>
</tr>
<tr>
<td style="text-align:left">name</td>
<td style="text-align:left">String</td>
<td style="text-align:left">重写字段名称。</td>
</tr>
<tr>
<td style="text-align:left">dataType</td>
<td style="text-align:left">Stirng</td>
<td style="text-align:left">重写字段类型。</td>
</tr>
<tr>
<td style="text-align:left">required</td>
<td style="text-align:left">boolean</td>
<td style="text-align:left">是否必填。</td>
</tr>
<tr>
<td style="text-align:left">example</td>
<td style="text-align:left">Stirng</td>
<td style="text-align:left">举例说明。</td>
</tr>
<tr>
<td style="text-align:left">hidden</td>
<td style="text-align:left">boolean</td>
<td style="text-align:left">是否在文档中隐藏该字段。</td>
</tr>
<tr>
<td style="text-align:left">allowEmptyValue</td>
<td style="text-align:left">boolean</td>
<td style="text-align:left">是否允许为空。</td>
</tr>
<tr>
<td style="text-align:left">allowableValues</td>
<td style="text-align:left">String</td>
<td style="text-align:left">该字段允许的值，当我们 API 的某个参数为枚举类型时，使用这个属性就可以清楚地告诉 API 使用者该参数所能允许传入的值。</td>
</tr>
</tbody>
</table>
</div>
<h4 id="FAQ"><a href="#FAQ" class="headerlink" title="FAQ"></a>FAQ</h4><h5 id="Required-String-parameter-39-xxxx-39-is-not-present？"><a href="#Required-String-parameter-39-xxxx-39-is-not-present？" class="headerlink" title="Required String parameter &#39;xxxx&#39; is not present？"></a><code>Required String parameter &#39;xxxx&#39; is not present</code>？</h5><p><img src="http://localhost:4000/2020/08/03/swagger%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8/003.png" alt></p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://wrr123.github.io/2020/07/31/package-json%E4%B8%AD%E5%8C%85%E7%9A%84%E7%89%88%E6%9C%AC%E5%8F%B7%E7%AC%A6%E5%8F%B7%E8%AF%A6%E8%A7%A3/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="田园隐士">
      <meta itemprop="description" content="talk is cheap, show me the code">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一缕烟气">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2020/07/31/package-json%E4%B8%AD%E5%8C%85%E7%9A%84%E7%89%88%E6%9C%AC%E5%8F%B7%E7%AC%A6%E5%8F%B7%E8%AF%A6%E8%A7%A3/" class="post-title-link" itemprop="url">package.json中包的版本号符号详解</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-07-31 14:41:02" itemprop="dateCreated datePublished" datetime="2020-07-31T14:41:02+08:00">2020-07-31</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2022-02-18 10:52:04" itemprop="dateModified" datetime="2022-02-18T10:52:04+08:00">2022-02-18</time>
              </span>

          <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>800</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>1 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h4 id="在node-js的文件package-json中，版本号前面的符号-和-的含义"><a href="#在node-js的文件package-json中，版本号前面的符号-和-的含义" class="headerlink" title="在node.js的文件package.json中，版本号前面的符号^和~的含义"></a>在node.js的文件package.json中，版本号前面的符号<code>^</code>和<code>~</code>的含义</h4><p>当我们使用最新版的node运行<code>npm install --save XXX</code>时，它会优先考虑使用插入符号(<code>^</code>),而不是使用波浪符号了(<code>~</code>)。</p>
<p>波浪符号(<code>~</code>): 它会更新到当前minor version(也就是中间的那个数据)中最新的版本，</p>
<p>插入符号(<code>^</code>): 它会更新到当前major version(也就是第一个数字)中最新的版本。</p>
<blockquote>
<p>最后解释下之前提到的minor verision和major version：</p>
<p>1.15.2对应就是MAJOR,MINOR.PATCH：1是marjor version；15是minor version；2是patch version。</p>
<p>MAJOR：这个版本号变化了表示有了一个不可以和上个版本兼容的大更改。</p>
<p>MINOR：这个版本号变化了表示有了增加了新的功能，并且可以向后兼容。</p>
<p>PATCH：这个版本号变化了表示修复了bug，并且可以向后兼容。</p>
</blockquote>
<h4 id="添加-package-json-文件中不存在的依赖包"><a href="#添加-package-json-文件中不存在的依赖包" class="headerlink" title="添加 package.json 文件中不存在的依赖包"></a>添加 package.json 文件中不存在的依赖包</h4><h4 id="package-json-和-package-lock-json-两个的区别"><a href="#package-json-和-package-lock-json-两个的区别" class="headerlink" title="package.json 和 package-lock.json 两个的区别"></a>package.json 和 package-lock.json 两个的区别</h4><blockquote>
<p><code>package-lock.json</code> 的作用就是用来保证我们的应用程序依赖之间的关系是一致的，兼容的；适合多人协作开发时保证每个人的依赖版本是一致的。</p>
</blockquote>
<p>当项目中不存在 <code>package-lock.json</code> 文件时，使用 <code>npm install</code> 时会自动生成这个文件。当 <code>package-lock.json</code> 存在时，则会安装文件中指定版本的依赖，并且安装速度会比不存在此文件时块很多。因为 <code>package-lock.json</code> 中已经存在依赖的版本，下载地址和整个 <code>node_modules</code> 的文件结构等信息。</p>
<blockquote>
<p>使用yarn同样也会自动生成package-lock.json文件，但是cnpm不会自动生成，并且也不会读取package-lock.json文件，只根据package.json下载依赖。</p>
</blockquote>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  


  
  <nav class="pagination">
    <a class="extend prev" rel="prev" href="/page/29/"><i class="fa fa-angle-left" aria-label="上一页"></i></a><a class="page-number" href="/">1</a><span class="space">&hellip;</span><a class="page-number" href="/page/29/">29</a><span class="page-number current">30</span><a class="page-number" href="/page/31/">31</a><span class="space">&hellip;</span><a class="page-number" href="/page/35/">35</a><a class="extend next" rel="next" href="/page/31/"><i class="fa fa-angle-right" aria-label="下一页"></i></a>
  </nav>



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">田园隐士</p>
  <div class="site-description" itemprop="description">talk is cheap, show me the code</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">347</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
        <span class="site-state-item-count">53</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
        <span class="site-state-item-count">115</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">田园隐士</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-area"></i>
    </span>
    <span title="站点总字数">587k</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    <span title="站点阅读时长">8:53</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://muse.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Muse</a> 强力驱动
  </div>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>




  




  
<script src="/js/local-search.js"></script>













  

  

  

</body>
</html>
